package com.dianjing.dianjing.controller;


import com.dianjing.dianjing.dto.input.InformInput;
import com.dianjing.dianjing.service.InformService;
import com.dianjing.dianjing.util.DataUtils;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 通知表 前端控制器
 * </p>
 *
 * @author LBG
 * @since 2022-11-09
 */
@RestController
@Api(tags = "通知模块")
@RequestMapping("/inform")
public class InformController {

    @Resource
    private InformService informService;

    @ApiOperation("发布通知")
    @PostMapping("/publishInform")
    public DataUtils publishInform(@RequestBody InformInput input){
        return informService.publishInform(input);
    }

    @ApiOperation("查看通知")
    @GetMapping("/showInform/{userId}")
    public DataUtils showInform(@PathVariable("userId") Long userId){
        return informService.showInform(userId);
    }

    @ApiOperation("根据id查看通知详情")
    @GetMapping("/showInformDetail/{informId}")
    public DataUtils showInformDetail(@PathVariable("informId") Long informId){
        return informService.showInformDetail(informId);
    }

    @ApiOperation("删除通知")
    @PostMapping("/removeInfo/{infoId}")
    public DataUtils removeInfo(@PathVariable("infoId") Long infoId){
        Boolean isRemoveInfoSuccess =  informService.removeInfo(infoId);
        if(isRemoveInfoSuccess) {
            // 成功
            return DataUtils.ok();
        }else {
            // 失败
            return DataUtils.error("删除通知失败");
        }
    }



}

